<template>
  <!-- 添加或修改销售信息管理对话框 -->
  <el-dialog :title="title" :visible.sync="open" width="80%" append-to-body :close-on-click-modal="true" v-dialogDrag>
    <el-form ref="form" :model="form" :rules="rules" label-width="120px">
      <el-tabs v-model="activeName" class="detail-tab" type="card">
        <el-tab-pane label="基本信息" name="first">

          <el-descriptions :column="2" border labelStyle="width: 160px; text-align: center;">
            <el-descriptions-item label="客户名称">
<!--              <div v-html="form.content"></div>-->
              {{form.customerName}}
            </el-descriptions-item>
            <el-descriptions-item label="供应商">
              {{form.supplierName}}
            </el-descriptions-item>
            <el-descriptions-item label="商品名称">
              {{form.goodsName}}
            </el-descriptions-item>
            <el-descriptions-item label="商品品牌">
              {{form.goodsBrand}}
            </el-descriptions-item>
            <el-descriptions-item label="商品型号">
              {{form.model}}
            </el-descriptions-item>
            <el-descriptions-item label="销售单价">
              {{form.goodsUnitPrice}}
            </el-descriptions-item>
            <el-descriptions-item label="销售数量">
              {{form.goodsCount}}
            </el-descriptions-item>
            <el-descriptions-item label="总价">
              {{form.goodsTotalPrice}}
            </el-descriptions-item>
            <el-descriptions-item label="销售日期">
              {{form.saleDate}}
            </el-descriptions-item>
            <el-descriptions-item label="是否开票">
              <dict-tag :options="dict.type.yes_no" :value="form.invoice"/>
<!--              {{form.invoice}}-->
            </el-descriptions-item>
            <el-descriptions-item label="发票编号">
              {{form.invoiceNo}}
            </el-descriptions-item>
            <el-descriptions-item label="是否回款">
              <dict-tag :options="dict.type.yes_no" :value="form.fundCallback"/>
<!--              {{form.fundCallback}}-->
            </el-descriptions-item>
            <el-descriptions-item label="销售人">
              {{form.saleName}}
            </el-descriptions-item>
            <el-descriptions-item label="备注">
              {{form.remark}}
            </el-descriptions-item>
          </el-descriptions>

        </el-tab-pane>
      </el-tabs>
    </el-form>
    <div slot="footer" class="dialog-footer">
      <!--      <el-button type="primary" @click="submitForm">确 定</el-button>-->
      <el-button @click="cancel">关 闭</el-button>
    </div>
  </el-dialog>
</template>

<script>
    import {addAction, getById, updateAction} from '@/api/manage'

    export default {
        name: "GoodsSaleInfo",
        dicts: ['goods_supplier', 'goods_customer', 'fund_callback', 'yes_no'],
        data() {
            return {
                // 遮罩层
                loading: true,
                activeName: "first",
                // 弹出层标题
                title: "",
                // 是否显示弹出层
                open: false,
                // 表单参数
                form: {},
                // 表单校验
                rules: {},
                url: {
                    getById: '/goodsSale/goodsSale/',
                    add: '/goodsSale/goodsSale/add',
                    edit: '/goodsSale/goodsSale/edit',
                },
            };
        },
        created() {

        },
        methods: {
            handleShow(row) {
                this.reset();
                const id = row.id || this.ids;
                getById(this.url.getById, id).then(response => {
                    this.form = response.data;
                    this.open = true;
                    this.title = "销售信息管理";
                });
            },
            updateTotlePrice() {
                let that = this;
                if (that.form.goodsCount && that.form.goodsUnitPrice) {
                    let totlePrice = this.functionNumberMul(that.form.goodsCount, that.form.goodsUnitPrice);
                    that.$set(that.form, "goodsTotalPrice", totlePrice);
                }
            },
            functionNumberMul(arg1, arg2) {
                var m = 0;
                var s1 = arg1.toString();
                var s2 = arg2.toString();
                try {
                    m += s1.split(".")[1].length;
                } catch (e) {
                }
                try {
                    m += s2.split(".")[1].length;
                } catch (e) {
                }
                return Number(s1.replace(".", "")) * Number(s2.replace(".", "")) / Math.pow(10, m);
            },
            selectCustomer(value) {
                let that = this;
                that.$nextTick(() => {
                    let arr = that.$refs.myselectCustomer;
                    for (let i = 0; i < arr.length; i++) {
                        if (arr[i].currentValue == value) {
                            that.form.customerName = arr[i].label;
                        }
                    }
                })
            },
            selectSupplier(value) {
                let that = this;
                that.$nextTick(() => {
                    let arr = that.$refs.myselectSsupplier;
                    for (let i = 0; i < arr.length; i++) {
                        if (arr[i].currentValue == value) {
                            that.form.supplierName = arr[i].label;
                        }
                    }
                })
            },
            selectUser(value) {
                let that = this;
                that.$nextTick(() => {
                    let arr = that.$refs.myselectUser;
                    for (let i = 0; i < arr.length; i++) {
                        if (arr[i].currentValue == value) {
                            that.form.saleName = arr[i].label;
                        }
                    }
                })
            },
            // 取消按钮
            cancel() {
                this.open = false;
                this.reset();
            },
            // 表单重置
            reset() {
                this.form = {
                    id: null,
                    goodsId: null,
                    goodsName: null,
                    goodsBrand: null,
                    goodsUnitPrice: null,
                    goodsCount: null,
                    goodsTotalPrice: null,
                    saleDate: null,
                    supplierId: null,
                    supplierName: null,
                    customerId: null,
                    customerName: null,
                    invoice: null,
                    invoiceId: null,
                    invoiceNo: null,
                    fundCallback: null,
                    receipt: null,
                    saleId: null,
                    saleName: null,
                    delFlag: null,
                    createBy: null,
                    createTime: null,
                    updateBy: null,
                    updateTime: null,
                    remark: null
                };
                this.resetForm("form");
            },
        }
    };
</script>
